<template>
  <div class="menu">
    <div v-show="!showCode" class="menu-bt" title="查看代码" @click="showCode = true">💻</div>
    <div v-show="showCode" class="menu-bt" title="显示预览" @click="showCode = false">❌</div>
    <div class="menu-bt show-menu" title="显示菜单" @click="showMenu = !showMenu">🚀</div>
  </div>
  <nav :show="showMenu">
    <a class="logo" href="https://gitee.com/light-year/css-demo" target="_blank" type="primary">
      <img height="28" width="95" src="https://gitee.com/static/images/logo-black.svg?t=158106664">
    </a>
    <div class="nav-list">
      <template v-for="m in modules" :key="m.name">
        <router-link :to="m.path" custom v-slot="{ navigate }">
          <div :active="m.name == $route.name" @click="navigate" @keypress.enter="navigate" role="link">
            <span>⚪</span><span>🔘</span> {{ m.describe }}
          </div>
        </router-link>
      </template>
    </div>
  </nav>
  <main>
    <router-view v-slot="{ Component }">
      <component ref="view" :is="Component" />
    </router-view>
    <CodeBlock
      v-show="showCode"
      :code="myCode"
      label=""
      theme="okaidia"
      lang="html"
    />
  </main>
</template>

<script>
import modules from "./views";

export default {
  name: "Pseudo3D",
  describe: "伪3D",
  data() {
    return{
      modules,
      showMenu: false,
      showCode: false,
      myCode: ''
    }
  },
  watch: {
    '$route.path'() {
      this.showCode = false;
      this.showMenu = false;
      this.$nextTick(() => {
        let code = this.$refs.view._.type._code;
        this.myCode = decodeURIComponent(code);
      })
    }
  }
}
</script>

<style lang="scss">
html,body{
  padding: 0;
  margin: 0;
  height: 100%;
  width: 100%;
  background-color: $--default-bg-color;
}
* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
  &:before,&:after{
    box-sizing: border-box;
  }
}
::-webkit-scrollbar {
  height: 10px;
  width: 10px;
}
::-webkit-scrollbar-corner {
  background-color: transparent;
}
::-webkit-scrollbar-thumb {
  border-radius: 10px;
  background: rgba(#999, .5);
  border: 1px solid rgba(#fff, .1);
}
::-webkit-scrollbar-track {
  background-color: transparent;
}
#app{
  display: flex;
  height: 100%;
  width: 100%;
  padding-left: 245px;
  position: absolute;
  top: 0;
  left: 0;
  transition: padding-left 0ms 200ms linear;
  > .menu{
    font-size: 20px;
    position: absolute;
    bottom: 15px;
    right: 10px;
    z-index: 20000;
    .menu-bt{
      display: flex;
      justify-content: center;
      align-items: center;
      width: 35px;
      height: 35px;
      border-radius: 50%;
      margin-top: 15px;
      background-color: #fff;
      box-shadow: 0 0 5px rgba(#000, .2);
      cursor: pointer;
      &.show-menu{
        display: none;
      }
    }
  }
  > nav{
    display: flex;
    flex-direction: column;
    flex: none;
    width: 240px;
    height: 100%;
    background-color: #fff;
    box-shadow: 0 0 5px rgba(#000, 0.1);
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10000;
    transform: translateX(0);
    transition: transform 200ms linear;

    .logo{
      display: block;
      flex: none;
      border-bottom: 1px solid #ddd;
      background-color: #f5f5f5;
      padding: 10px 0 10px 10px;
    }
    .nav-list{
      flex: auto;
      min-height: 0;
      overflow-y: auto;
      div{
        padding: 4px 10px;
        cursor: pointer;
        span:nth-child(2){
          display: none;
        }
        &[active="true"] {
          background-color: #eee;
          span:first-child{
            display: none;
          }
          span:nth-child(2){
            display: inline;
          }
        }
      }
    }
  }
  > main{
    flex: auto;
    min-width: 0;
    height: 100%;
    overflow: auto;
    position: relative;
    z-index: 1;
    > .v-code-block{
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      z-index: 10000;
      .v-code-block--code,
      pre{
        height: 100% !important;
      }
    }
  }
}
@media screen and (max-width: 1050px) {
  #app {
    padding-left: 0;
    transition: padding-left 0ms 0ms linear;
    > nav{
      position: absolute;
      top: 0;
      left: 0;
      z-index: 10000;
      transform: translateX(-100%);
      &[show="true"]{
        transform: translateX(0);
      }
    }
    > .menu{
      .menu-bt.show-menu{
        display: flex;
      }
    }
  }
}
</style>
